
<div style="font-size:1.2em">
  <h1>Import products</h1>
  <p>excel format should be as follows, do not skip fields it will cause an import error just simply keep the field blank if you wish to skip it.</p>
  <p><br/> </p>
  <p>name,description,price,image,category id, product code, restaurant id number</p>
  <p><br/> </p> 
  <p>To make multiple prices you should seperate each price by a semicolon ;<br> <br> </p>
  <p><em>Example row: Hotdog, a juicy frank, 1.50;3.50;5.50, 4, hotdog01, 1</em></p>
  <p><a href="test.csv" >Click here to download a sample csv file</a></p>
  <br/> 
</div>
<?php
require_once(dirname(__FILE__) . "/../core/safeParam.php");
if ($_POST['save'] != "") {
  $csv  = array();
  $file = fopen($_FILES['file']['tmp_name'], 'r');
  while (($result = fgetcsv($file)) !== false) {
    $csv[] = $result;
  } //($result = fgetcsv($file)) !== false
  fclose($file);
  for ($i = 0; $i < count($csv); $i++) {
    $insert[$i]['name']        = $csv[$i][0];
    $insert[$i]['description'] = $csv[$i][1];
    $insert[$i]['price']       = serialize(explode(";", $csv[$i][2]));
    $insert[$i]['image']       = $csv[$i][3];
    $insert[$i]['cat']         = $csv[$i][4];
    $insert[$i]['code']        = $csv[$i][5];
    $insert[$i]['rid']         = $csv[$i][6];
    $query                     = $database->insert_array('menu_item', $insert[$i]);
  } //$i = 0; $i < count($csv); $i++
  echo '<script type="text/javascript"> alert("Products Imported"); </script>';
} //$_POST['save'] != ""
?>

<form action="index.php?edit=import" enctype="multipart/form-data" method="post">
  Upload File: <input type="file" name="file"> <input type="submit" name="save" value="Submit">
</form>
